package com.feige.common.result;


/**
 * @author carlo
 */
public class ErrorHandler {
    /**
     * 异常的状态码，从枚举中获得 {@link EResultCode}
     */
    private Integer code;

    /**
     * 异常的消息，从枚举中得到
     */
    private String desc;

    /**
     * 异常的名字
     */
    private String exception;

    public static ErrorHandler failed(String desc) {
        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setCode(EResultCode.FAILED.getCode());
        errorHandler.setDesc(desc);
        return errorHandler;
    }

    public static ErrorHandler failed(Integer code, String desc) {
        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setCode(code);
        errorHandler.setDesc(desc);
        return errorHandler;
    }

    public static ErrorHandler failed(Integer code, String desc, Throwable throwable) {
        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setCode(code);
        errorHandler.setDesc(desc);
        errorHandler.setException(throwable.getClass().getName());
        return errorHandler;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getException() {
        return exception;
    }

    public void setException(String exception) {
        this.exception = exception;
    }
}
